import {
	defineConfig
} from "vite";
import path from "path";
import uni from "@dcloudio/vite-plugin-uni";
import {
	visualizer
} from "rollup-plugin-visualizer";
// import commonjs from '@rollup/plugin-commonjs';

// https://vitejs.dev/config/
export default defineConfig({
	plugins: [
		// commonjs(),
		uni(),
		visualizer(),
		{ // 自定义插件禁用vite:vue插件的devToolsEnabled，强制编译 vue 模板时 inline 为 true
			name: 'fix-vite-plugin-vue',
			configResolved(config) {
				const plugin = config.plugins.find((p) => p.name === 'vite:vue')
				if (plugin && plugin.api && plugin.api.options) {
					plugin.api.options.devToolsEnabled = false
				}
			},
		},
	],
	resolve: {
		// https://cn.vitejs.dev/config/#resolve-alias
		alias: {
			// 设置路径
			"~": path.resolve(__dirname, "."),
			// 设置别名
			"@": path.resolve(__dirname, "./src")
		},
		// https://cn.vitejs.dev/config/#resolve-extensions
		extensions: [".mjs", ".js", ".ts", ".jsx", ".tsx", ".json", ".vue"]
	},
	server: {
		port: 5100,
		fs: {
			// Allow serving files from one level up to the project root
			allow: [".."]
		}
	}
});